<?php
namespace Modules\Home\Controllers;

class UserWalletActivationCodeLogController extends ControllerBase {
  public function initialize() {
    parent::initialize();

    $this -> _checkLogin();
    $this -> view -> setLayout('index');
  }

  public function indexAction() {
    $this -> tag -> prependTitle('激活码记录');

    $currentPage = abs($this -> request -> getQuery('page', 'int', 1));
    if($currentPage <= 0) {
      $currentPage = 1;
    }

    $sessionGetUser = $this -> session -> get('user');

    $builderUserWalletActivationCodeLog = $this -> modelsManager -> createBuilder()
      -> from([
        'uwacl' => 'Common\\Models\\UserWalletActivationCodeLogModel'
      ])
      -> where('uwacl.user_id = ' . $sessionGetUser['user_id'])
      -> columns(
        'uwacl.user_wallet_activation_code_log_id, uwacl.type, uwacl.active, uwacl.create_time, uwacl.amount, uwacl.amount_new, uwacl.amount_old'
      )
      -> orderBy('uwacl.user_wallet_activation_code_log_id DESC');

    $pagerUserWalletActivationCodeLog = new \Phalcon\Paginator\Pager(new \Phalcon\Paginator\Adapter\QueryBuilder([
      'builder' => $builderUserWalletActivationCodeLog,
      'limit' => 10,
      'page' => $currentPage
    ]), [
      'layoutClass' => 'Modules\\Home\\Libraries\\Paginator\\Pager\\Layout\\Bootstrap',
      'rangeLength' => 5,
      'urlMask' => '?page={%page_number}'
    ]);

    $this -> view -> setVar('pagerUserWalletActivationCodeLog', $pagerUserWalletActivationCodeLog);
  }
}
?>